package com.musichord.core.message;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MetaMessage;

import com.musichord.core.helper.MidiInfo;

public class TempoMessage extends MetaMessage {
	public TempoMessage(int bpm) {
		super();
		int mpq = 60000000 / bpm;
		this.data = new byte[3];
		this.length = 3;
		data[0] = (byte) ((mpq >> 16) & 0xFF);
		data[1] = (byte) ((mpq >> 8) & 0xFF);
		data[2] = (byte) (mpq & 0xFF);
		try {
			this.setMessage(MidiInfo.TEMPO_CHANGE, this.data, this.length);
		} catch (InvalidMidiDataException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
